package bTree.LeetCode;

import java.util.Arrays;

public class 分发糖果 {
    public int candy(int[] ratings) {
        int []nums=new int[ratings.length];
        nums[0]=1;
        for (int i = 1; i < ratings.length; i++) {
            if (ratings[i]>ratings[i-1]){
                nums[i]=nums[i-1]+1;
            }else {
                nums[i]=1;
            }
        }
        for (int i = ratings.length-1; i >0; i--) {
            if (ratings[i-1]>ratings[i]){
                nums[i-1]=Math.max(nums[i-1],nums[i]+1);
            }
        }
        return Arrays.stream(nums).sum();
    }
}